﻿namespace GuiaTest
{
    using System;
    using System.Collections.Generic;
    using System.Threading;
    using Guia.Core;
    using Guia.Elements;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using WpfTestApplication;

    /// <summary>
    /// Summary description for StatusBarTest
    /// </summary>
    [TestClass]
    public class StatusBarTest : AbstractWindowTest
    {
        protected override Type TestWindowType()
        {
            return typeof(StatusBarTestWindow);
        }

        protected override string TestWindowName()
        {
            return "StatusBarTestWindow";
        }

        [TestMethod]
        public void TestReadContent()
        {
            StatusBar statusBar = window.Get<StatusBar>("statusBar");
            Assert.IsNotNull(statusBar);
            Label[] statusBarItems = statusBar.GetStatusBarItems();
            Assert.AreEqual(2, statusBarItems.Length);
            Assert.AreEqual("Statusbar Text", statusBarItems[0].TextValue);
            Assert.AreEqual("Status", statusBarItems[1].TextValue);
        }

        [TestMethod]
        public void TestReadContentIndexer()
        {
            StatusBar statusBar = window.Get<StatusBar>("statusBar");
            Assert.IsNotNull(statusBar);
            Label[] statusBarItems = statusBar.GetStatusBarItems();
            Assert.AreEqual(2, statusBarItems.Length);
            Assert.AreEqual("Statusbar Text", statusBar[0].TextValue);
            Assert.AreEqual("Status", statusBar[1].TextValue);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void TestReadContentIndexerOutOfRangeTooSmall()
        {
            StatusBar statusBar = window.Get<StatusBar>("statusBar");
            Assert.IsNotNull(statusBar);
            Label item = statusBar[-1];
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void TestReadContentIndexerOutOfRangeTooBig()
        {
            StatusBar statusBar = window.Get<StatusBar>("statusBar");
            Assert.IsNotNull(statusBar);
            Label item = statusBar[3];
        }

        [TestMethod]
        public void TestReadChangedContent()
        {
            StatusBar statusBar = window.Get<StatusBar>("statusBar");
            Assert.IsNotNull(statusBar);
            Label[] statusBarItems = statusBar.GetStatusBarItems();
            Assert.AreEqual(2, statusBarItems.Length);
            Assert.AreEqual("Status", statusBarItems[1].TextValue);
            window.Get<Button>("buttonStateOn").Invoke();
            Delay.ForMilliseconds(10);
            Assert.AreEqual("On", statusBarItems[1].TextValue);
            window.Get<Button>("buttonStateOff").Invoke();
            Delay.ForMilliseconds(10);
            Assert.AreEqual("Off", statusBarItems[1].TextValue);
            Assert.AreEqual("Off", statusBar[1].TextValue);
        }

    }
}
